package com.example._03thymeleaf.controller;

import com.example._03thymeleaf.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;

@Controller
public class HelloController {
    @RequestMapping("/test1")
    public String test1(ModelMap m) {
        m.addAttribute("message", "hello 第一个thymeleaf");
        return "_01hello";
    }
    @GetMapping("/test2")
    public String test2(Model m){
        m.addAttribute("username","张三");
        return "_2string";
    }
    @RequestMapping("/test3")
    public String ifunless(ModelMap map) {
        map.addAttribute("flag", "no");
        return "_3ifUnless";
    }

    private List<User> getUserList(){
        List<User> list=new ArrayList<User>();
        User user1=new User("大牛",12,"123456");
        User user2=new User("小牛",6,"123563");
        User user3=new User("纯洁的微笑",66,"666666");
        list.add(user1);
        list.add(user2);
        list.add(user3);
        return  list;
    }
    @RequestMapping("/test4")
    public String list(ModelMap map) {
        map.addAttribute("users", getUserList());
        return "_04list";
    }

    @RequestMapping("/test5")
    public String url(Model m) {
        m.addAttribute("type", "link");
        m.addAttribute("pageId", "springcloud/2017/09/11/");
        m.addAttribute("img", "http://www.ityouknow.com/assets/images/neo.jpg");
        return "_05url";
    }

    @RequestMapping("/test6")
    public String switchcase(Model m) {
        m.addAttribute("sex", "woman");
        return "_06switch";
    }

    @RequestMapping("/test7")
    public String inline(Model m) {
        m.addAttribute("username", "张三");
        m.addAttribute("userid", "15");
        return "_07inline";
    }

}
